package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Address;
import com.itheima.service.AddressManagementService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/mobelAddressManagement")
@RestController
public class mobelAddressManagementController {

    @Reference
    private AddressManagementService addressManagementService;

    @RequestMapping("/findAllAddress")
    public Result findAllAddress() {
        try {
            List<Address> all = addressManagementService.findAll();
            return new Result(true, "查询机构信息成功", all);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询机构信息失败");
        }
    }
    @RequestMapping("/findHotAddress")
    public Result findHotAddress(){
      try {
         List<Address>  addressList=addressManagementService.findHotAddress();
         return new Result(true,"查询热门城市成功",addressList);
      }catch (Exception e){
          e.printStackTrace();
          return new Result(false,"查询热门城市失败");
      }
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        System.out.println(id);
        try {
            Address address = addressManagementService.findById(id);
          return  new Result(true,"查询机构地址信息成功",address);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询机构地址信息失败");
        }
    }
}
